package test;
//写一个递归方法，输入一个非负整数，返回组成它的数字之和
public class RecursionAdd{
    public static void main(String[] args) {
        int num = 1997;
        System.out.println(recursionAdd(num));
    }
    public static int recursionAdd(int num) {
        //小于 10，递归终止条件
        if (num < 10) {
            return num;
        }
        //(1997) = (199) + 7
        //(199) = (19) + 9
        //(19) = (1) + 9
        return num % 10 + recursionAdd(num / 10);
    }
}
